package com.umgsai.thread.thread01;

public class MyThread16 extends Thread {
	private long i = 0;

	public long getI() {
		return i;
	}

	public void setI(long i) {
		this.i = i;
	}

	@Override
	public void run() {
		while (true) {
			i++;
		}
	}
	
	public static void main(String[] args) {
		try {
			MyThread16 thread = new MyThread16();
			thread.start();
			System.out.println("Main thread started, time=" + System.currentTimeMillis() + ", i=" + thread.getI());
			Thread.sleep(2000);
			
			thread.suspend();//暂停
			System.out.println("A suspended, time=" + System.currentTimeMillis() + ", i=" + thread.getI());
			Thread.sleep(2000);
			System.out.println("A suspended, time=" + System.currentTimeMillis() + ", i=" + thread.getI());
			
			thread.resume();//恢复执行
			System.out.println("A resumed, time=" + System.currentTimeMillis() + ", i=" + thread.getI());
			Thread.sleep(2000);
			
			thread.suspend();//暂停
			System.out.println("B suspended, time=" + System.currentTimeMillis() + ", i=" + thread.getI());
			Thread.sleep(2000);
			System.out.println("B suspended, time=" + System.currentTimeMillis() + ", i=" + thread.getI());
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
